{% extends "blog/base.html" %}
{% load blog_tags %}

{% block title %}
	My first Blog
{% endblock %}

{% block content %}
<article class="col-xs-12 col-md-8">
<h1>My Blog List </h1>
	{% if tag %}
		<h2>Post tagged with"{{ tag.name }}"</h2>
	{% endif %}
	{% for post in posts %}
	
	<!--<h2><a href="{{ post.id}}">{{post.title}}</h2>-->  

	<h2><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></h2>
	<!-- h2的內容要調用models中的def get_absolute_url數據，才能以year/month/day/post的形式存儲在數據庫中，urls中才能匹配正則表達式-->
	<p>
		Tags:
			{% for tag in post.tags.all %}
			 <a href="{% url 'blog:post_list_tag' tag.slug %}">{{tag.name}}</a>
			  {% if not forloop.last %},{% endif %}
			{% endfor %}
	</p>	
	<p>Published {{ post.published }} by {{post.author}}</p>
	{% endfor %}
	{% include 'blog/post/pagination.html' %}
</article>
<aside class="col-xs-6 col-md-4">
	<h3>My blogs</h3>
	<p>I have written {% total_posts %} posts.</p>
	
	<h3>Latest Posts</h3>
	{% latest_posts 2 %}

	<h3>Most commented posts</h3>
	{% most_commented_posts as comments %}
	<ul>
	  {% for post in comments %}
	  <li><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></li>
	  {% endfor %}
	</ul>
</aside>
{% endblock %}
 